package com.zdsoft.blp.zongbuju.wode.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zdsoft.blp.R;

import java.util.List;
import java.util.Map;

/**
 * Created by pc on 2016/9/2.
 */
public class TiShiYinAdapter extends BaseAdapter {

    private List<Map<String,Object>> list;
    private Context mContext;
    private int index ;
    public TiShiYinAdapter(List<Map<String,Object>> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
    }


    public void change(int position){
        if(position!=index){
            index=position;
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.wode_tsyitem, null);
            holder.iv = (ImageView) convertView.findViewById(R.id.iv);
            holder.tv = (TextView) convertView.findViewById(R.id.tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if(position==index){
            holder.iv.setImageResource(R.drawable.checked);
        }else {
            holder.iv.setImageResource(R.drawable.pressed);
        }
        holder.tv.setText(list.get(position).get("title").toString());
        return convertView;
    }

    class ViewHolder {
        ImageView iv;
        TextView tv;
    }
}
